/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package roles;

import avenue.MyWindowEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.persistence.EntityManager;


import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellEditor;
import javax.swing.DefaultCellEditor;

import model.DBManager;
import model.Module;
import model.RolePermission;
import model.UserRole;

import users.*;
/**
 *
 * @author Aggelos
 */
public class EditRoleForm2 extends javax.swing.JFrame 
{
    EntityManager em;
    
    UserRole userRoleFromListRolesForm;
    RolePermission  rolePermissionFromListRolesForm;
    
    boolean readOnly;
    boolean initialiseUpdate;
    
   // List <UserRole> tlist = new  ArrayList<>();
    
     RolePermission  rp22;
    

    /**
     * Creates new form EditUserForm
     */
    public EditRoleForm2() 
    {
        em = DBManager.em;
        initComponents();
        
         RolePermission  rp2 = new RolePermission();
         em.persist(rp2);
         selectPermsByUserRoleLIST.add(rp2);
    }
    
     public EditRoleForm2(UserRole ur, boolean readOnly) 
     {
        em = DBManager.em;
        
        userRoleFromListRolesForm=ur;
        this.readOnly = readOnly;
        initComponents();
    }
     
      public EditRoleForm2(UserRole ur2, boolean readOnly,boolean update) 
      {
        em = DBManager.em;
        if ( !(em.getTransaction().isActive()) ){
            em.getTransaction().begin();
           }
        initialiseUpdate = update;

        userRoleFromListRolesForm=ur2;
        this.readOnly = readOnly;
        initComponents();
////////////////////////////////////////////////////     
//////            RolePermission  rp22 = new RolePermission();
//////            em.persist(rp22);
//////            selectPermsByUserRoleLIST.add(rp22);
////////////////////////////////////////////////////
        if(initialiseUpdate==false)
          {
            rp22 = new RolePermission();
            em.persist(rp22);
            selectPermsByUserRoleLIST.add(rp22);
          }

    }
      
      public EditRoleForm2(UserRole ur2, RolePermission rp2, boolean readOnly,boolean update) 
      {
        em = DBManager.em;
        if ( !(em.getTransaction().isActive()) ){
            em.getTransaction().begin();
           }
        initialiseUpdate = update;

        
        userRoleFromListRolesForm=ur2;
        rolePermissionFromListRolesForm = rp2;
        
        this.readOnly = readOnly;
        initComponents();

        if(initialiseUpdate==false)
          {
            em.persist(rolePermissionFromListRolesForm);
            selectPermsByUserRoleLIST.add(rolePermissionFromListRolesForm);
          }

    }
  
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        userRoleGuiObject = userRoleFromListRolesForm;
        selectPermsByUserRoleQUERY = em.createQuery("select rp from RolePermission rp where rp.roleId=:userRole").setParameter("userRole",userRoleGuiObject);
        selectPermsByUserRoleLIST = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(selectPermsByUserRoleQUERY.getResultList());
        moduleQuery = java.beans.Beans.isDesignTime() ? null : em.createQuery("select f from Module f");
        moduleList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(moduleQuery.getResultList());
        modRend = new renderers.moduleComboBoxRenderer();
        moduleTCR = new renderers.TableCellModulesRenderer();
        userRolesTCR = new renderers.TableCellUserRolesRenderer();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        roleNameTextField = new javax.swing.JTextField();
        saveButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        userRolesTable = new javax.swing.JTable();
        canCreateCheckBox = new javax.swing.JCheckBox();
        canRetrieveCheckBox = new javax.swing.JCheckBox();
        canUpdateCheckBox = new javax.swing.JCheckBox();
        canDeleteCheckBox = new javax.swing.JCheckBox();
        modulesComboBox = new javax.swing.JComboBox();
        StationLevelAccessCheckBox = new javax.swing.JCheckBox();
        idRoleLBL = new javax.swing.JLabel();
        UpdateSelectionsButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        moduleTCR.setText("tableCellModulesRenderer1");

        userRolesTCR.setText("tableCellUserRolesRenderer1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("Όνομα Ρόλου : ");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, userRoleGuiObject, org.jdesktop.beansbinding.ELProperty.create("${roleName}"), roleNameTextField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.gif"))); // NOI18N
        saveButton.setText("Αποθήκευση");
        saveButton.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                saveButtonActionPerformed(evt);
            }
        });

        cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cancel.gif"))); // NOI18N
        cancelButton.setText("Ακυρο");
        cancelButton.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                cancelButtonActionPerformed(evt);
            }
        });

        userRolesTable.getTableHeader().setReorderingAllowed(false);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, selectPermsByUserRoleLIST, userRolesTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${canCreate}"));
        columnBinding.setColumnName("Can Create");
        columnBinding.setColumnClass(java.io.Serializable.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${canRetrieve}"));
        columnBinding.setColumnName("Can Retrieve");
        columnBinding.setColumnClass(java.io.Serializable.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${canUpdate}"));
        columnBinding.setColumnName("Can Update");
        columnBinding.setColumnClass(java.io.Serializable.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${canDelete}"));
        columnBinding.setColumnName("Can Delete");
        columnBinding.setColumnClass(java.io.Serializable.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${moduleId}"));
        columnBinding.setColumnName("Module Id");
        columnBinding.setColumnClass(model.Module.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${roleId}"));
        columnBinding.setColumnName("Ονομα ρολου");
        columnBinding.setColumnClass(model.UserRole.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${stationLevelAccess}"));
        columnBinding.setColumnName("Station Level Access");
        columnBinding.setColumnClass(java.io.Serializable.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(userRolesTable);
        //////////////////////////////

        TableCellEditor editor = new DefaultCellEditor(modulesComboBox);
        DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();

        TableCellEditor editor2 = new DefaultCellEditor(roleNameTextField);
        DefaultTableCellRenderer tableRenderer2 = new DefaultTableCellRenderer();

        /////////////////////////////////////////////
        userRolesTable.getColumnModel().getColumn(2).setResizable(false);
        /////////////////////
        userRolesTable.getColumnModel().getColumn(5).setCellEditor(editor);
        userRolesTable.getColumnModel().getColumn(5).setCellRenderer(moduleTCR);

        userRolesTable.getColumnModel().getColumn(6).setCellEditor(editor2);
        userRolesTable.getColumnModel().getColumn(6).setCellRenderer(userRolesTCR);
        ///////////////////

        ////////

        canCreateCheckBox.setText("Create");
        canCreateCheckBox.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                canCreateCheckBoxActionPerformed(evt);
            }
        });

        canRetrieveCheckBox.setText("Retrieve");
        canRetrieveCheckBox.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                canRetrieveCheckBoxActionPerformed(evt);
            }
        });

        canUpdateCheckBox.setText("Update");
        canUpdateCheckBox.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                canUpdateCheckBoxActionPerformed(evt);
            }
        });

        canDeleteCheckBox.setText(" Delete");
        canDeleteCheckBox.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                canDeleteCheckBoxActionPerformed(evt);
            }
        });

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, moduleList, modulesComboBox);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, modRend, org.jdesktop.beansbinding.ObjectProperty.create(), modulesComboBox, org.jdesktop.beansbinding.BeanProperty.create("renderer"));
        bindingGroup.addBinding(binding);

        modulesComboBox.addMouseListener(new java.awt.event.MouseAdapter()
        {
            public void mouseClicked(java.awt.event.MouseEvent evt)
            {
                modulesComboBoxMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt)
            {
                modulesComboBoxMouseEntered(evt);
            }
        });
        modulesComboBox.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                modulesComboBoxActionPerformed(evt);
            }
        });
        modulesComboBox.addPropertyChangeListener(new java.beans.PropertyChangeListener()
        {
            public void propertyChange(java.beans.PropertyChangeEvent evt)
            {
                modulesComboBoxPropertyChange(evt);
            }
        });

        StationLevelAccessCheckBox.setText("STATION LEVEL ACCESS");
        StationLevelAccessCheckBox.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                StationLevelAccessCheckBoxActionPerformed(evt);
            }
        });

        idRoleLBL.setText("");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, userRoleGuiObject, org.jdesktop.beansbinding.ELProperty.create("${id}"), idRoleLBL, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        UpdateSelectionsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Refresh.png"))); // NOI18N
        UpdateSelectionsButton.setText("Ανανέωση");
        UpdateSelectionsButton.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                UpdateSelectionsButtonActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        jLabel2.setText("Διαχείριση Ρόλου");

        jLabel3.setText("Δικαιώματα για: Διαχείριση Χρηστών");

        jLabel4.setText("Δικαιώματα για: Διαχείριση Πελατών");

        jLabel5.setText("Δικαιώματα για: Διαχείριση Προγραμμάτων");

        jLabel6.setText("Δικαιώματα για: Είσπραξη Διοδίων");

        jLabel7.setText("Δικαιώματα για: Φόρτιση Κάρτας");

        jLabel8.setText("Δικαιώματα για: Κίνηση");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 894, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator2)
                    .addComponent(jSeparator4)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(roleNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(39, 39, 39)
                                .addComponent(idRoleLBL))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(canCreateCheckBox)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(canRetrieveCheckBox)
                                .addGap(18, 18, 18)
                                .addComponent(canUpdateCheckBox)
                                .addGap(18, 18, 18)
                                .addComponent(canDeleteCheckBox)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(modulesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(StationLevelAccessCheckBox))
                            .addComponent(UpdateSelectionsButton)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(saveButton)
                                .addGap(18, 18, 18)
                                .addComponent(cancelButton))
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(13, 13, 13)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(roleNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(idRoleLBL))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(canCreateCheckBox)
                    .addComponent(canRetrieveCheckBox)
                    .addComponent(canUpdateCheckBox)
                    .addComponent(canDeleteCheckBox)
                    .addComponent(modulesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(StationLevelAccessCheckBox))
                .addGap(18, 18, 18)
                .addComponent(UpdateSelectionsButton)
                .addGap(14, 14, 14)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(cancelButton))
                .addGap(28, 28, 28)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addComponent(jLabel8)
                .addContainerGap(39, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // TODO add your handling code here:
        
        
        MyWindowEvent we = new MyWindowEvent(this, WindowEvent.WINDOW_CLOSED,false);
        for (WindowListener l : this.getWindowListeners()) {
            l.windowClosed(we);
       }
       this.setVisible(false); 
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        // TODO add your handling code here:

           MyWindowEvent we = new MyWindowEvent(this, WindowEvent.WINDOW_CLOSED,true);
        for (WindowListener l : this.getWindowListeners()) {
            l.windowClosed(we);
       }
       this.setVisible(false); 
          
        
    }//GEN-LAST:event_saveButtonActionPerformed

    private void canCreateCheckBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_canCreateCheckBoxActionPerformed
    {//GEN-HEADEREND:event_canCreateCheckBoxActionPerformed
        // TODO add your handling code here  
    }//GEN-LAST:event_canCreateCheckBoxActionPerformed

    private void canRetrieveCheckBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_canRetrieveCheckBoxActionPerformed
    {//GEN-HEADEREND:event_canRetrieveCheckBoxActionPerformed
        // TODO add your handling code here:   
    }//GEN-LAST:event_canRetrieveCheckBoxActionPerformed

    private void canUpdateCheckBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_canUpdateCheckBoxActionPerformed
    {//GEN-HEADEREND:event_canUpdateCheckBoxActionPerformed
        // TODO add your handling code here:   
    }//GEN-LAST:event_canUpdateCheckBoxActionPerformed

    private void canDeleteCheckBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_canDeleteCheckBoxActionPerformed
    {//GEN-HEADEREND:event_canDeleteCheckBoxActionPerformed
        // TODO add your handling code here:  
    }//GEN-LAST:event_canDeleteCheckBoxActionPerformed

    private void StationLevelAccessCheckBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_StationLevelAccessCheckBoxActionPerformed
    {//GEN-HEADEREND:event_StationLevelAccessCheckBoxActionPerformed
        // TODO add your handling code here:    
    }//GEN-LAST:event_StationLevelAccessCheckBoxActionPerformed

    private void modulesComboBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_modulesComboBoxActionPerformed
    {//GEN-HEADEREND:event_modulesComboBoxActionPerformed
        // TODO add your handling code here:      
    }//GEN-LAST:event_modulesComboBoxActionPerformed

    private void modulesComboBoxMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_modulesComboBoxMouseClicked
    {//GEN-HEADEREND:event_modulesComboBoxMouseClicked
        // TODO add your handling code here:   
    }//GEN-LAST:event_modulesComboBoxMouseClicked

    private void modulesComboBoxPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_modulesComboBoxPropertyChange
    {//GEN-HEADEREND:event_modulesComboBoxPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_modulesComboBoxPropertyChange

    private void modulesComboBoxMouseEntered(java.awt.event.MouseEvent evt)//GEN-FIRST:event_modulesComboBoxMouseEntered
    {//GEN-HEADEREND:event_modulesComboBoxMouseEntered
        // TODO add your handling code here:          
    }//GEN-LAST:event_modulesComboBoxMouseEntered

    private void UpdateSelectionsButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_UpdateSelectionsButtonActionPerformed
    {//GEN-HEADEREND:event_UpdateSelectionsButtonActionPerformed
        // TODO add your handling code here:

        if(roleNameTextField.getText().isEmpty())
          {
            JOptionPane.showMessageDialog(this,"please enter name");
          }else 
       //if(!roleNameTextField.getText().isEmpty())
          {
            if(canCreateCheckBox.isSelected()) {
                userRolesTable.getModel().setValueAt(1, 0, 0);
              }
            if(!canCreateCheckBox.isSelected()) {
                userRolesTable.getModel().setValueAt(0, 0, 0);
              }  
//////////////////////////////////////////
            if(canRetrieveCheckBox.isSelected()){
                userRolesTable.getModel().setValueAt(1, 0, 1);
              }
            if(!canRetrieveCheckBox.isSelected()){
                userRolesTable.getModel().setValueAt(0, 0, 1);
              }  
//////////////////////////////////////////
            if(canUpdateCheckBox.isSelected()){
                userRolesTable.getModel().setValueAt(1, 0, 2);
               }
            if(!canUpdateCheckBox.isSelected()){
                userRolesTable.getModel().setValueAt(0, 0, 2);
              }
 //////////////////////////////////////////           
             if(canDeleteCheckBox.isSelected()){
                userRolesTable.getModel().setValueAt(1, 0, 3);
             }
            if(!canDeleteCheckBox.isSelected()){
                userRolesTable.getModel().setValueAt(0, 0, 3);
              } 
 //////////////////////////////////////////  
            if(StationLevelAccessCheckBox.isSelected()){
                userRolesTable.getModel().setValueAt(1, 0, 7);
            }
            if(!StationLevelAccessCheckBox.isSelected()){
                userRolesTable.getModel().setValueAt(0, 0, 7);
              }
 //////////////////////////////////////////  

           Module mm = (Module)modulesComboBox.getSelectedItem();
           userRolesTable.getModel().setValueAt(mm, 0, 5); 
 //////////////////////////////////////////          
           userRoleFromListRolesForm.setRoleName(roleNameTextField.getText());
           userRolesTable.getModel().setValueAt(userRoleFromListRolesForm, 0, 6);
          
            userRolesTable.repaint();
          }
    }//GEN-LAST:event_UpdateSelectionsButtonActionPerformed
    
    
public void pp()
{
//        for(int i=0; i<selectPermsByUserRoleLIST.size(); i++)
//          {
//            System.out.println(selectPermsByUserRoleLIST.get(i).getCanCreate());
//            System.out.println(selectPermsByUserRoleLIST.get(i).getCanRetrieve());
//            System.out.println(selectPermsByUserRoleLIST.get(i).getCanUpdate());
//            System.out.println(selectPermsByUserRoleLIST.get(i).getCanDelete());
//          }
    System.out.println(modulesComboBox.getSelectedIndex());

}
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EditUserForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EditUserForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EditUserForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EditUserForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EditRoleForm2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox StationLevelAccessCheckBox;
    private javax.swing.JButton UpdateSelectionsButton;
    private javax.swing.JCheckBox canCreateCheckBox;
    private javax.swing.JCheckBox canDeleteCheckBox;
    private javax.swing.JCheckBox canRetrieveCheckBox;
    private javax.swing.JCheckBox canUpdateCheckBox;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel idRoleLBL;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator4;
    private renderers.moduleComboBoxRenderer modRend;
    private java.util.List<Module> moduleList;
    private javax.persistence.Query moduleQuery;
    private renderers.TableCellModulesRenderer moduleTCR;
    private javax.swing.JComboBox modulesComboBox;
    private javax.swing.JTextField roleNameTextField;
    private javax.swing.JButton saveButton;
    private java.util.List<RolePermission> selectPermsByUserRoleLIST;
    private javax.persistence.Query selectPermsByUserRoleQUERY;
    private model.UserRole userRoleGuiObject;
    private renderers.TableCellUserRolesRenderer userRolesTCR;
    private javax.swing.JTable userRolesTable;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
